<template>
  <div id="home">
    <div class="header">
      <div style="width: 200px;padding-left: 30px;font-weight: bold;color: white;">iTest</div>
      <span></span>
    </div>
    <div class="user">
      <el-card style="width: 40%;margin: 10px">
        <el-form ref="form" :model="form" label-width="80px">
          <el-form-item label="用户名">
            <el-input v-model="form.username" disabled></el-input>
          </el-form-item>
          <el-form-item label="昵称">
            <el-input v-model="form.nickName"></el-input>
          </el-form-item>
          <el-form-item label="年龄">
            <el-input v-model="form.age"></el-input>
          </el-form-item>
          <el-form-item label="性别">
            <el-radio v-model="form.sex" label="男">男</el-radio>
            <el-radio v-model="form.sex" label="女">女</el-radio>
            <el-radio v-model="form.sex" label="未知">未知</el-radio>
          </el-form-item>
          <el-form-item label="地址">
            <el-input v-model="form.address"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input v-model="form.password" show-password></el-input>
          </el-form-item>
        </el-form>
        <div style="text-align: center">
          <el-button type="primary" @click="update">保存</el-button>
          <el-button type="primary" @click="jump">返回</el-button>
        </div>
      </el-card>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "Person",
  data(){
    return{
      form:{}
    }
  },
  created() {
    let str = sessionStorage.getItem("user") || "{}";
    this.form = JSON.parse(str);
  },
  methods:{
    update(){
      request.put("/api/user",this.form).then(res => {
        console.log(res);
        if (res.code === '0'){
          this.$message({
            type:"success",
            message:"更新成功"
          })
          sessionStorage.setItem("user",JSON.stringify(this.form));
        }else {
          this.$message({
            type:"error",
            message:res.msg
          });
        }
      });
    },
    jump(){
      this.$router.push("/news")
    }
  }
}
</script>

<style scoped>
#home {
  width: 100vw;
  height: 100vh;
  background: url("../assets/view2.jpg") no-repeat;
  background-size: cover;
  overflow: hidden;
  opacity:0.8;
}
.user {
  margin-top: 30px;

}

</style>
